<?php
apf_require_class('Solr_Bll_BaseBiz');
class Solr_Bll_AppBiz extends Solr_Bll_BaseBiz {

    private static $instance;

    public static function &get_instance() {
        if(!self::$instance){
           	self::$instance = new self();
        }
        return self::$instance;
    }

    public function insert_application($host_id,$webapp_id,$memo){
        if(!$host_id||!$webapp_id)return false;
        $app_dao=$this->get_app_dao();
        return $app_dao->insert_application($host_id,$webapp_id,$memo);
    }

    public function get_apps_list($hostname_id,$port){
        $app_dao=$this->get_app_dao();
        $tmp=$app_dao->get_apps_list($hostname_id,$port);
        if($tmp){
            foreach($tmp as $v){
                $res[$v['id']]=$v;
            }
        }
        return $res;
    }

    public function get_idx_port_list(){
        $app_dao=$this->get_app_dao();
        $res=$app_dao->get_idx_port_list();
        return $res;
    }

    public function insert_hostname($hostname){
        if(!$hostname)return false;
        $app_dao=$this->get_app_dao();
        return $app_dao->insert_hostname($hostname);
    }

    public function get_all_hostname(){
        $app_dao=$this->get_app_dao();
        $tmp=$app_dao->get_all_hostname();
        if($tmp){
            foreach($tmp as $v){
                $res[$v['id']]=$v;
            }
        }
        return $res;
    }

    public function insert_webapp($webapp,$solrname,$port){
        if(!$webapp||!$solrname||!$port)return false;
        $app_dao=$this->get_app_dao();
        if(!preg_match('/^\/.*/',$webapp))$webapp='/'.$webapp;
        return $app_dao->insert_webapp($webapp,$solrname,$port);
    }

    public function get_all_webapp(){
        $app_dao=$this->get_app_dao();
        $tmp=$app_dao->get_all_webapp();
        if($tmp){
            foreach($tmp as $v){
                $res[$v['id']]=$v;
            }
        }
        return $res;
    }

    public function get_port_list(){
        $app_dao=$this->get_app_dao();
        $res=$app_dao->get_port_list();
        return $res;
    }
}